package com.loan.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.loan.common.annotation.Log;
import com.loan.common.constant.UserConstants;
import com.loan.common.core.controller.BaseController;
import com.loan.common.core.domain.Result;
import com.loan.common.enums.BusinessType;
import com.loan.system.domain.ConfigEntity;
import com.loan.system.domain.SysConfig;
import com.loan.system.domain.req.ConfigEntityReq;
import com.loan.system.service.AppConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author shiguang
 * @date 2022年09月18日 19:44
 */
@Validated
@Api(value = "系统设置控制器", tags = {"系统设置控制器"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/app/config")
public class ConfigController extends BaseController {

    private final AppConfigService appConfigService;

    @ApiOperation("根据参数键名查询参数值")
    //@SaCheckPermissio("app:config:query")
    @GetMapping(value = "/detail")
    public Result<ConfigEntityReq> getDetail(){
        return Result.ok(appConfigService.getDetail());
    }

    /**
     * 新增参数配置
     */
    @ApiOperation("新增参数配置")
    //@SaCheckPermissio("app:config:add")
    @Log(title = "参数管理", businessType = BusinessType.INSERT)
    @PostMapping
    public Result<Void> add(@Validated @RequestBody ConfigEntityReq config) {
        return toAjax(appConfigService.insertConfig(config));
    }

    /**
     * 修改参数配置
     */
    @ApiOperation("修改参数配置")
    //@SaCheckPermissio("app:config:edit")
    @Log(title = "参数管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result<Void> edit(@Validated @RequestBody ConfigEntityReq config) {
        return toAjax(appConfigService.updateConfig(config));
    }
}
